﻿namespace Smart.Utils.Net
{
    using System;
    using System.Net;
    using System.Net.Mail;
    using System.Text;

    public class Email
    {
        private MailMessage message;
        private SmtpClient smtpClient;

        public Email(string your_mail, string your_name)
        {
            MailAddress address = new MailAddress(your_mail, your_name, Encoding.UTF8);
            this.smtpClient = new SmtpClient();
            this.smtpClient.Port = 0x19;
            this.message = new MailMessage();
            this.message.From = address;
            this.message.IsBodyHtml = true;
            this.message.BodyEncoding = Encoding.UTF8;
        }

        public void AddBccAddress(string address, string name)
        {
            this.message.Bcc.Add(new MailAddress(address, name, Encoding.UTF8));
        }

        public void AddCCAddess(string address, string name)
        {
            this.message.CC.Add(new MailAddress(address, name, Encoding.UTF8));
        }

        public void AddToAddress(string address, string name)
        {
            this.message.To.Add(new MailAddress(address, name, Encoding.UTF8));
        }

        public void AssignGmailSSL(string username, string password)
        {
            this.smtpClient.Host = "smtp.gmail.com";
            this.smtpClient.Port = 0x24b;
            this.smtpClient.EnableSsl = true;
            this.smtpClient.Credentials = new NetworkCredential(username, password);
        }

        public void AssignSmtp(string Smtp)
        {
            this.smtpClient.Host = Smtp;
        }

        public void AssignSSLSmtp(string SmtpServer, int Port, string MailAddress, string Password)
        {
            this.smtpClient.Host = SmtpServer;
            this.smtpClient.Port = Port;
            this.smtpClient.EnableSsl = true;
            this.smtpClient.Credentials = new NetworkCredential(MailAddress, Password);
        }

        public void Content(string subject, string textbody)
        {
            this.message.Subject = subject;
            this.message.Body = textbody;
        }

        public void Send()
        {
            try
            {
                this.smtpClient.Send(this.message);
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }

        public string Body
        {
            get
            {
                return this.message.Body;
            }
            set
            {
                this.message.Body = value;
            }
        }

        public bool isHTML
        {
            get
            {
                return this.message.IsBodyHtml;
            }
            set
            {
                this.message.IsBodyHtml = value;
            }
        }

        public string Subject
        {
            get
            {
                return this.message.Subject;
            }
            set
            {
                this.message.Subject = value;
            }
        }
    }
}

